<?php

declare(strict_types=1);

namespace App\Model\PssModel;

use App\Model\BaseModel\BasePssModel;
use App\Service\Code\Normal;
class OrderRecharge extends BasePssModel
{
    public $table = 'order_recharge';
    public $recharge_status = [
        '0' => '待充值',
        '1' => '充值成功',
        '2' => '充值失败'
    ];
    
    /**
     * 获取在线充值结果
     * @param array $param
     */
    public function getAlinPayRechargeResult( $param = [] )
    {
        $binfo = $param['binfo'];
        $body = $param['body'];
        if( empty($body['order_sn']) ) {
            return Normal::returnCode(Normal::FAIL,"except param order_sn");
        }
        
        $order_sn = $body['order_sn'];
        $recharge = $this->info(['bid' => $binfo['bid'],'order_sn' => $order_sn],[
            'order_sn',
            'pay_sn',
            'pay_way',
            'money',
            'recharge_status',
            'recharge_result',
            'remark'
        ]);
        
        if( empty($recharge) ) {
            return Normal::returnCode(Normal::FAIL,"充值数据不能为空");
        }
        
        $recharge['recharge_status_name'] = $this->recharge_status[$recharge['recharge_status']]??'未定义';
        return Normal::returnCode(Normal::SUC,"获取成功",$recharge);
    }
}
